<%--
  Created by IntelliJ IDEA.
  User: 15433
  Date: 2019/7/13
  Time: 11:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    String e = request.getParameter("error");
%>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>register</title>
    <link rel="stylesheet" type="text/css" href="js/re.css">
</head>

<body onload="initBody()">
    <%
    // 获取浏览器发送过来的cookie, 获取用户信息
    Cookie[] cookies = request.getCookies();
    String username = "";
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if ("username".equals(cookie.getName())) {
                username = cookie.getValue();
            }
        }
    }
%>

<div id="content">
    <div class="login-header">
        <img src="Image/logo.png">
    </div>
    <form action="RegisterServlet" method="post">
        <div class="login-input-box">
            <span class="icon icon-user"></span>
            <input type="text" type="text" name="Account" value="<%=request.getParameter("Account")==null?"":request.getParameter("Account")%>"
                   placeholder="Please enter your username">
        </div>
        <div class="login-input-box">
            <span class="icon icon-password"></span>
            <input type="password" name="Password" value="<%=request.getParameter("Password")==null?"":request.getParameter("Password")%>"
                   placeholder="Please enter your password">
        </div>
        <div class="login-input-box">
            <span class="icon icon-password"></span>
            <input type="password" placeholder="Please confirm your password">
        </div>
        <div class="captcha" >
            <span class="icon "></span>
            <input input type="text" name="CAPTCHA">
            <img id="verify">
            <input  type="button" value="看不清? 换一张" id="btn">
        </div>

        <div class="login-button-box">
            <button   type="submit" value="登录" onclick="
 if(Account.value===''){
    alert('用户名不能为空');
    return false;
}else if(Password.value===''){
    alert('密码不能为空');
    return false;
}else if(Check.value===''){
    alert('确认密码不能为空');
    return false;
}else if(CAPTCHA.value===''){
    alert('验证码不能为空');
    return false;
}else if(Password.value!==Check.value){
    alert('密码不一致');
    return false;
}" >Register</button>

        </div>
    </form>
    <div class="logon-box">
        <a href="login.jsp">Login</a>
    </div>
</div>
<span style="color: red" class="mes">
    <%
        if(request.getAttribute("error")!=null){
    %>
        此用户名已存在
    <%
        }
        if(request.getAttribute("verifyerror")!=null){
    %>
        验证码错误
    <%
        }
    %>
</span>

    <script type="text/javascript">

        document.getElementById("btn").onclick = function () {
            // 获取img元素
            // 为了让浏览器发送请求到servlet, 所以一定要改变src
            changeImg();
        };

        function initBody() {
            changeImg();
            if (<%=e!=null%>) {
                document.getElementById("error").innerHTML =<%='\"'+e+'\"'%>;
            }
        }

        function changeImg() {
            document.getElementById("verify").src =
                "./CaptchaServlet?time=" + new Date().getTime();
        }
    </script>
</body>
</html>
